from sqlmodel import SQLModel, Field
from pydantic import field_serializer

class WpUserBase(SQLModel):
    """Waveup用户表基础数据模型"""
    uid: int = Field(default=0, description="用户ID")
    userOpenId: str = Field(default="", index=True, max_length=64, description="Waveup用户OpenID")
    mobileNo: str = Field(default="", max_length=32, description="用户手机号")
    email: str = Field(default="", max_length=64, description="用户邮箱")
    nickName: str = Field(default="", max_length=64, description="用户昵称")
    avatar: str = Field(default="", max_length=256, description="用户头像URL")
    kycStatus: int = Field(default=0, description="实名认证状态 0、未认证 1、已认证")

class WpUserCreate(WpUserBase):
    """Waveup用户表创建数据模型"""
    pass

class WpUserOutput(SQLModel):
    """Waveup用户表输出数据模型"""
    mobileNo: str = Field(default="", max_length=32, description="用户手机号")
    nickName: str = Field(default="", max_length=64, description="用户昵称")
    avatar: str = Field(default="", max_length=256, description="用户头像URL")
    kycStatus: int = Field(default=0, description="实名认证状态 0、未认证 1、已认证")

    @field_serializer("mobileNo")
    def mask_mobile(self, mobileNo: str) -> str:
        """手机号中间4位脱敏"""
        if not mobileNo or len(mobileNo) < 7:
            return mobileNo
        return mobileNo[:3] + "****" + mobileNo[-4:]
